package br.com.rglariguet.rgportal.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.rglariguet.rgportal.Hora;
import br.com.rglariguet.rgportal.dao.HoraDAO;

@Repository
@Transactional
public class HoraDAOImpl implements HoraDAO {

	private final SessionFactory factory;
	
	@Autowired
	public HoraDAOImpl (SessionFactory factory){
		this.factory = factory;
	}
	
	private Session getSession() {
		return factory.getCurrentSession();
	}

	@Override
	public void salvar(Hora hora) {         				
		getSession().save(hora);  		
	}
	
	@Override
	public List<Hora> listarTodos() {
		return (List<Hora>)getSession().createQuery("from Hora as hora order by hora.dia").list();
	}

	@Override
	public Hora buscarPorId(Long id) {
		return (Hora) getSession().get(Hora.class, id);
	}
	
	@Override
	public void alterar(Hora hora) {
		getSession().update(hora);
	}

	@Override
	public void excluir(Hora hora) {
		getSession().delete(hora);
	}
	
}
